package de.fhaugsburg.games.boardgames;

import java.util.List;
import java.util.Random;
import java.util.Vector;

/**
 * A pool which can be filled up with objects <T>. Also you can remove
 * random objects severally.
 * @author r4smus
 *
 * @param <T>
 */
public class RandomPool<T> {
	
	private Random random;
	private List<T> collection;
	
	public RandomPool() {
		random = new Random();
		collection = new Vector<T>();
	}
	/**
	 * puts one object in the pool.
	 * @param o
	 */
	public void put(T o){
		collection.add(o);
	}
	
	/**
	 * takes one random object out of the pool.
	 * @return
	 */
	public T take(){
		int randomIndex = random.nextInt(collection.size());
		T randomObject = collection.get(randomIndex);
		collection.remove(randomObject);
		return randomObject;
	}
	
	/**
	 * checks if the pool has objects, if the pool is empty it returns
	 * true, else it returns false.
	 * @return
	 */
	public boolean empty(){
		if(collection.size() <= 0) return true; //<= oder == 0 ?
		else return false;
		
	}
	
	public String toString(){
		return collection.toString();
	}

}
